﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using System.Data;
using AspNetCs.Bll;
using AspNetCs.Model;
using AspNetCs.Enumerations.Channel_Enum;
public partial class SacrificeMuAdd : BasePage
{
    protected int classid = 0;
    protected int id = 0;
    protected string whereStr = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
        }

        if (Request["ClassId"] != null)
        {
            classid = StringHelper.isNumber_int(Request["ClassId"].ToString());
        }
        UserPhoto_Class_Model md = UserPhoto_Bll.CreateNew.GetModelClass(classid);

        Base_CurrPath += " >> " + md.ClassName;

        memorial_model cemeModel = Memorial_Bll.CreateNew.GetModel(id);
        if (cemeModel.Id <= 0)
        {
            Response.Write("<script>alert('当前列表不存在!');history.back();</script>");

        }

        if (!Page.IsPostBack)
        {

            try
            {
                ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
            }
            catch
            {
                ViewState["UrlReferrer"] = null;
            }
            bindpic();
        }
        if (Base_GetLoginInfo.GetUserID > 0)
        {
            this.Panel1.Visible = true;
            this.Panel2.Visible = false;
            this.UserName.Text = Base_GetUserInfo.UserName;
            this.UserName.Enabled = false;
        }
        else
        {
            this.Panel2.Visible = true;
            this.Panel1.Visible = false;
        }
        //  this.AspNetPager1.UrlRewritePattern = "SacrificeAdd-" + classid + "-" + id + ".Aspx";

    }

    protected void bindpic()
    {
        whereStr = " classid=" + classid;
        Pager p = new Pager();
        p.Obj = DataList1;
        p.TableName = "UserPhoto";
        p.WhereStr = whereStr;
        p.Orderfld = "id";
        p.PageSize = this.AspNetPager1.PageSize;
        p.PageIndex = this.AspNetPager1.CurrentPageIndex;
        p.OrderType = "asc";
        p.ControlBind();

        this.AspNetPager1.RecordCount = p.recordcount();









        //DataTable dt = UserPhoto_Bll.CreateNew.GetDataTable(" classid=" + classid);
        //this.DataList1.DataSource = dt;
        //this.DataList1.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string str = "";
        if (Request["SelectId"] != null)
        {
            str = Request["SelectId"].ToString();
        }


        string truename = Txt_OtherName.Text;
        string cnt = StringHelper.HtmlEncrypt(Content.Text);

        SacrificeList_Model Model = new SacrificeList_Model();
        Model.ChannelId = Channel_Type.gravestone.ToString();
        Model.PhotoId = StringHelper.isNumber_int(str);
        Model.UserId = Base_GetLoginInfo.GetUserID;
        Model.UserName = Base_GetLoginInfo.GetUserName;
        Model.Content = cnt;
        Model.TrueName = truename;
        Model.TypeId = id;
        Model.Classid = classid;
        Model.NetIp = StringHelper.Ip();
        if (Model.PhotoId <= 0)
        {
            Response.Write("<script>alert('请选择祭祀内容');history.back();</script>");
        }
        NetMu_Model CurrMu = NetMu_Bll.CreatNew.getNetMuDetailInfo(id);
        if (SacrificeList_Bll.CreateNew.SaCrificePoint(classid, "公墓:" + CurrMu.MuId + "(" + CurrMu.MuName + ")祭祀，", Base_GetLoginInfo.GetUserID) > 0)
        {


            int AddInt = SacrificeList_Bll.CreateNew.Add(Model);

            if (AddInt > 0)
            {
                Response.Write("<script>alert('祭祀成功！');location.href='SacrificeMuAdd-" + classid + "-" + id + ".Aspx'</script>");
                Response.End();
            }

        }
        else {
            Response.Write("<script>alert('对不起，你点数不够，不能祭祀！');location.href='SacrificeMuAdd-" + classid + "-" + id + ".Aspx'</script>");
            Response.End();
                
        }

    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bindpic();
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            if (DataList1.Items.Count <= 0)
            {
                Panel pl = e.Item.FindControl("Panel3") as Panel;
                pl.Visible = true;
            }
        }


    }
}
